﻿namespace OnWork.Admin.Util
{
    /// <summary>
    /// 接口通用内容
    /// </summary>
    public class ReturnModel
    {
        /// <summary>
        /// 接口返回的公用对象
        /// </summary>
        public ReturnModel()
        {
        }

        /// <summary>
        /// 公用
        /// </summary>
        /// <param name="code"></param>
        /// <param name="data"></param>
        public ReturnModel(int code, object data)
        {
            Code = code;
            Data = data;
        }

        /// <summary>
        /// 状态码
        /// </summary>
        public int Code { get; set; } = 200;

        /// <summary>
        /// 是否成功
        /// </summary>
        public bool Ok { get; set; }

        /// <summary>
        /// 信息
        /// </summary>
        public string Msg { get; set; }

        /// <summary>
        /// 返回数据
        /// </summary>
        public object Data { get; set; }

        /// <summary>
        /// 添加成功
        /// </summary>
        /// <param name="message">消息内容</param>
        /// <returns></returns>
        public static ReturnModel AddSuccess(string message = "添加数据成功!")
        {
            return new ReturnModel() { Msg = message, Ok = true };
        }

        /// <summary>
        /// 添加失败
        /// </summary>
        /// <param name="message">消息内容</param>
        /// <param name="title">返回消息标题</param>
        /// <returns></returns>
        public static ReturnModel AddError(string message = "添加数据失败!")
        {
            return new ReturnModel() { Msg = message, Ok = false };
        }

        /// <summary>
        /// 删除成功
        /// </summary>
        /// <param name="total">完成的数量</param>
        /// <param name="message">消息内容</param>
        /// <param name="title">返回消息标题</param>
        /// <returns></returns>
        public static ReturnModel DelSuccess(int total = 1, string message = "删除数据成功!")
        {
            return new ReturnModel() { Msg = message, Ok = true };
        }

        /// <summary>
        /// 删除失败
        /// </summary>
        /// <param name="rows">添加的数量</param>
        /// <param name="msg">成功信息!</param>
        /// <returns></returns>
        public static ReturnModel DelError(string message = "添加数据失败!")
        {
            return new ReturnModel() { Msg = message, Ok = false };
        }

        /// <summary>
        /// 更新成功
        /// </summary>
        /// <param name="total">完成的数量</param>
        /// <param name="message">消息内容</param>
        /// <param name="title">返回消息标题</param>
        /// <returns></returns>
        public static ReturnModel UpdateSuccess(int total = 1, string message = "修改数据成功!")
        {
            return new ReturnModel() { Msg = message, Ok = true, };
        }

        /// <summary>
        /// 更新失败
        /// </summary>
        /// <param name="message">消息内容</param>
        /// <param name="title">返回消息标题</param>
        /// <returns></returns>
        public static ReturnModel UpdateError(string message = "修改数据失败!")
        {
            return new ReturnModel() { Msg = message, Ok = false };
        }
    }

    public class ReturnModel<T> where T : class
    {
        /// <summary>
        /// 状态码
        /// </summary>
        public int Code { get; set; }

        /// <summary>
        /// 是否成功
        /// </summary>
        public bool IsSuccess { get; set; }

        /// <summary>
        /// 信息
        /// </summary>
        public string Message { get; set; }

        /// <summary>
        /// 返回数据
        /// </summary>
        public T Data { get; set; }
    }
}